//
//  NRWShareImageAlertView.m
//  New_Runway
//
//  Created by 邢毅 on 2018/5/28.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWShareImageAlertView.h"

@interface NRWShareImageAlertView()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation NRWShareImageAlertView

- (instancetype)init
{
    self = [[NSBundle mainBundle] loadNibNamed:@"NRWShareImageAlertView" owner:self options:nil].firstObject;
    if (self) {
        
        self.frame = [UIScreen mainScreen].bounds;
        self.layer.cornerRadius = 13;
    }
    return self;
}

- (void)setImage:(UIImage *)image {
    
    _image = image;
    
    self.imageView.image = image;
}

- (void)show {
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 1;
    }];
}

- (void)dismiss {
    
    [UIView animateWithDuration:0.25 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
        if ([self.delegate respondsToSelector:@selector(shareImageAlertViewDidDisappear:)]) {
            
            [self.delegate shareImageAlertViewDidDisappear:self];
        }
    }];
}

- (IBAction)shareBtnDidClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(shareImageAlertView:shareBtn:didClickWithImage:)]) {
        
        [self.delegate shareImageAlertView:self shareBtn:sender didClickWithImage:self.image];
    }
}
- (IBAction)closeBtnDidClick:(UIButton *)sender {
    
    [self dismiss];
}

@end
